package  
{
	import flash.utils.Dictionary;

	public dynamic class CLocale// extends Dictionary
	{
		private static var _lan:CLocale
		
		public static function get res():CLocale
		{
			if(_lan==null)
				_lan=new CLocale();
			return _lan;
		}
		
		/**
		 * 得到类容
		 */
		public static function getValue(key:String,...arg):*
		{
			var s:String=res.getValue(key);
			
			for(var i:int=0;i<arg.length;i++)
				s=s.replace("{"+i+"}",arg[i]);
			
			return s;			
		}
		
		public function CLocale()
		{
			
		}
		
		/**
		 * 解压指定格式的文本类容
		 */
		public static function loadLanguage(msg:String):void
		{
			decompression(msg);
		}
		
		/**
		 * 得到值
		 */
		public function getValue(key:String):*
		{
			if(this.hasOwnProperty(key))
				return this[key];
			else
				return ""
		}
		
		/**
		 * 设置值
		 */
		public function setValue(key:String,value:*):void
		{
			this[key]=value;
		}
		//****************私有成员******************
		
		/**
		 * 解压
		 */
		private static function decompression(data:String):void
		{
			var rows:Array=data.split("\r\n");//所有行
			var line:String;
			var columns:Array;//列
			var p:String;
			var v:String;
			for(var i:int=2;i<rows.length;i++)
			{
				line=rows[i];
				if(line.indexOf("////")==0)
					break;
				
				columns=line.split("\t");
				p=columns[0];
				v=columns[1];
				res.setValue(p,v);
			}
		}
		
	}
}